﻿/*
 * Created by SharpDevelop.
 * User: Masy Freddy
 * Date: 15/09/2011
 * Time: 17:45
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.IO;
using System.Xml.Serialization;

using MetaVideoEditorEvolved.Helper;

namespace ReaderMediaBrowser
{
	/// <summary>
	/// Description of ConfigurationManager.
	/// </summary>
	public static class ConfigurationManager
	{
		private static string configurationPath;
		
		static ConfigurationManager()
		{
			configurationPath = Path.Combine(ApplicationPath.AddInConfiguration, "ReaderMediaBrowser.config");
		}
		
		public static void Serialize(ConfigurationAddIn configurationAddIn)
		{
			using(StreamWriter sw = new StreamWriter(configurationPath))
			{
				new XmlSerializer(typeof(ConfigurationAddIn)).Serialize(sw, configurationAddIn);
			}
		}
		
		public static ConfigurationAddIn Deserialize()
		{
			if(File.Exists(configurationPath))
			{
				using (StreamReader sr = new StreamReader(configurationPath))
				{
					return new XmlSerializer(typeof(ConfigurationAddIn)).Deserialize(sr) as ConfigurationAddIn;
				}
			}
			
			return null;
		}
	}
}
